package com.hybao.pojo.dao;

import org.springframework.jdbc.core.JdbcTemplate;

import com.hybao.pojo.ormaaping.LoginInfo;

public class LoginInfoDao {
	private JdbcTemplate jdbcTemplate;

	public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}
	
	public LoginInfo getLoginInfo(String uid){
		String sql = "select USER_ID,SESSION_KEY,LAST_LOGIN from HYB_LOGIN where USER_ID = ?";
		Object[] args = {uid};
		return jdbcTemplate.queryForObject(sql,LoginInfo.class,args);
	}
	
	public void updateLoginInfo(String uid){
		String sql = "update HYB_LOGIN set LAST_LOGIN = now() where USER_ID = ?";
		Object[] args = {uid};
		jdbcTemplate.update(sql,args);
	}
	
	public void insertLoginInfo(String uid, String sessionKey){
		String sql = "insert into HYB_LOGIN (GMT_CREATE,GMT_MODIFIED,USER_ID,SESSION_KEY,LAST_LOGIN) values (now(),now(),?,?,now())";
		Object[] args = {uid,sessionKey};
		jdbcTemplate.update(sql,args);
	}
}
